package com.zhs.demoutil.demo2;

import java.util.List;

class TieredPricingStrategy implements PricingStrategy {
    private final List<PriceTier> tiers;

    public TieredPricingStrategy(List<PriceTier> tiers) {
        this.tiers = tiers;
    }

    @Override
    public double calculatePrice(int quantity) {
        double totalPrice = 0.0;
        for (PriceTier tier : tiers) {
            int tierQuantity = Math.min(quantity, tier.getQuantity());
            totalPrice += tierQuantity * tier.getPrice();
            quantity -= tierQuantity;
            if (quantity <= 0) {
                break;
            }
        }
        return totalPrice;
    }
}

